package cn.crawler.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class CrawlerSer extends HttpServlet {

	
	protected void crawler(HttpServletRequest request,HttpServletResponse response) throws ServletException ,IOException{
		String url = request.getParameter("url");
		if (url == null)
			return;
		Document doc = Jsoup.connect(url).get();
		Element link = doc.select("a").first();
		String fa = link.text();
		System.out.println(fa);
	}
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       crawler(request, response);
    }

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       crawler(request, response);
    }
	
}
